<?php
include("../common.inc.php");
InitGP(array("page","action","bid","delids","state")); //初始化變量全局返回
include("function_common.php");
//初始化對象
include(INC_PATH."/groupbond.class.php");
$gb=new GroupBondClass();

if(empty($action)){
	InitGP(array("gid","sn","uid")); //初始化變量全局返回
	if(!empty($gid))$wherestr[]="gid='{$gid}'";
	if(!empty($sn))$wherestr[]="sn like '%{$sn}%'";
	if(!empty($uid))$wherestr[]="uid={$uid}";
	$wherestr[]="state=4";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//條件匯總
	
	//獲取當前頁碼
	$total=$gb->getcount($wheresql); 							  //總信息數
	$pagesize=15;												  //一頁顯示信息數
	$page = isset($page) ? max(1, intval($page)) : 1;             //處理頁碼變量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$gb->getdata("$offset,$pagesize",$wheresql); //獲取團購數據
	
	//包含後台模板文件
	include("tpl/groupbond_list.htm");
}elseif ($action=="edit") {
	InitGP(array("bid","gid","sn","password","endtime","usetime","uid","Submit")); //初始化變量全局返回
	if(!empty($Submit)){
		//處理提交動作
		if(isset($gid) && isset($bid)){
		//處理數據
		$gid=GetNum($gid);
		$uid=GetNum($uid);
		$sn=Char_cv($sn);
		$password=Char_cv($password);
		$endtime=strtotime($endtime);
		$endtime=strtotime($usetime);
		$arrayedit=array(
		"gid"=>$gid,
		"uid"=>$uid,
		"sn"=>$sn,
		"password"=>$password,
		"endtime"=>$endtime,
		"usetime"=>$usetime
		);
		//執行編輯操作
		include(INC_PATH."/member.class.php");
		$m=new memberclass();
		$user=$m->getone($uid);
		$arrayedit['uname']=$user['uname'];
		
		$info=$gb->edit($bid,$arrayedit);
		if($info=="OK"){
			showmsg("編輯團購卷成功!","groupbond_list.php");//成功
		}else showmsg($info,"groupbond_add.php");//出錯！
	}else showmsg("缺少參數","groupbond_add.php");//出錯！
		
	}else {
	
	//編輯團購信息表單
	$dataedit=$gb->getdata(1,"bid={$bid}");
	$value=$dataedit[0];//獲取第一條記錄
	//包含後台模板文件
	include("tpl/groupbond_edit.htm");	
	}
}elseif ($action=="del" && !empty($bid)){
	//執行刪除操作
	$bid=GetNum($bid);
	$info=$gb->del($bid);
	if($info=="OK")showmsg("刪除團購卷成功！","groupbond_list.php");
	else showmsg($info,"groupbond_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("沒有選擇任何對象！","groupbond_list.php");exit;}//空選擇
	//執行刪除多個操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$gb->del($id);
	}
	if($info=="OK")showmsg("刪除團購卷成功！","groupbond_list.php");
	else showmsg($info,"groupbond_list.php");
}elseif ($action=="refuse"){
	$bid=GetNum($bid);
	$state=GetNum($state);
	
	$info = $gb->updateState($bid,$state);
	if($info=="OK") showmsg("退款團購卷成功！","groupbond_list.php");
	else showmsg($info,"groupbond_list.php");
	//將團購卷移至退款單	
}


?>

